package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.ElderFamilyDto;
import com.zzyl.nursing.dto.QueryDeviceDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.FamilyMemberPageVo;
import com.zzyl.nursing.vo.HourlyDataVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.health.HealthMassgeVo;
import com.zzyl.nursing.vo.health.HealthReturnVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IDeviceService deviceService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    /**
     * 绑定老人家属
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ElderFamilyDto elderFamilyDto) {
        familyMemberService.add(elderFamilyDto);
        return AjaxResult.success();
    }


    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    public R<List<FamilyMemberElderVo>> my() {
        return R.ok(familyMemberService.my());
    }


    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/list-by-page")
    public R<List<FamilyMemberPageVo>> listByPage(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return R.ok(familyMemberService.listByPage(pageNum, pageSize));
    }

    /**
     * 解除绑定
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(Long id) {
        return familyMemberService.deleteById(id);
    }

    /**
     * 查询健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public R<HealthReturnVo> queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        String deviceName = deviceDto.getDeviceName();
        String productKey = deviceDto.getProductKey();
        HealthMassgeVo healthMassgeVo = familyMemberService.queryDevicePropertyStatus(deviceName,productKey);
        HealthReturnVo healthReturnVo = new HealthReturnVo();
        healthReturnVo.setList(healthMassgeVo);
        return R.ok(healthReturnVo);
    }


    /*
     *按天统计查询指标数据
     */
    @GetMapping("queryDeviceDataListByDay")
    public R<List<HourlyDataVo>> queryDeviceDataListByDay(@RequestParam String iotId,
                                                          @RequestParam Long startTime,
                                                          @RequestParam Long endTime,
                                                          @RequestParam String functionId){
        return R.ok(familyMemberService.queryDeviceDataListByDay(iotId, startTime, endTime, functionId));
    }


    /*
     *按周统计查询指标数据
     */
    @GetMapping("queryDeviceDataListByWeek")
    public R<List<HourlyDataVo>> queryDeviceDataListByWeek(@RequestParam String iotId,
                                                          @RequestParam Long startTime,
                                                          @RequestParam Long endTime,
                                                          @RequestParam String functionId){
        return R.ok(familyMemberService.queryDeviceDataListByWeek(iotId, startTime, endTime, functionId));
    }

}

